<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="java,String," />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.0" />






<meta name="description" content="在做字符串拼接的时候，最常适用的几种 + 、concat方法，以及StringBuilder（StringBuffer。两者实现一样，StringBuffer是线程安全的） +“+”可以字符串与字符串或非字符串拼接在一起，形成字符串。java使用StringBuffer对象重载了+号操作符，通过append方法对字符串进行拼接。（JAVA不允许对其他操作符进行重载）The Java languag">
<meta name="keywords" content="java,String">
<meta property="og:type" content="article">
<meta property="og:title" content="java中字符创拼接方法对比">
<meta property="og:url" content="https://gitee.com/shuhao/2018/01/19/java中字符创拼接方法对比/index.html">
<meta property="og:site_name" content="Niki">
<meta property="og:description" content="在做字符串拼接的时候，最常适用的几种 + 、concat方法，以及StringBuilder（StringBuffer。两者实现一样，StringBuffer是线程安全的） +“+”可以字符串与字符串或非字符串拼接在一起，形成字符串。java使用StringBuffer对象重载了+号操作符，通过append方法对字符串进行拼接。（JAVA不允许对其他操作符进行重载）The Java languag">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://gitee.com/blog/images/java/java_add_class.png">
<meta property="og:updated_time" content="2018-05-28T01:30:53.924Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="java中字符创拼接方法对比">
<meta name="twitter:description" content="在做字符串拼接的时候，最常适用的几种 + 、concat方法，以及StringBuilder（StringBuffer。两者实现一样，StringBuffer是线程安全的） +“+”可以字符串与字符串或非字符串拼接在一起，形成字符串。java使用StringBuffer对象重载了+号操作符，通过append方法对字符串进行拼接。（JAVA不允许对其他操作符进行重载）The Java languag">
<meta name="twitter:image" content="https://gitee.com/blog/images/java/java_add_class.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Mist',
    sidebar: {"position":"right","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://gitee.com/shuhao/2018/01/19/java中字符创拼接方法对比/"/>





  <title> java中字符创拼接方法对比 | Niki </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?cb9f0585e406f878cb2f29c89ad3cdb7";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Niki</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">天道酬勤</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-categories"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/shuhao/blog/2018/01/19/java中字符创拼接方法对比/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Fang ShuHao">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/head.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Niki">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                java中字符创拼接方法对比
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-19T15:14:54+08:00">
                2018-01-19
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/java/" itemprop="url" rel="index">
                    <span itemprop="name">java</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>在做字符串拼接的时候，最常适用的几种 + 、concat方法，以及StringBuilder（StringBuffer。两者实现一样，StringBuffer是线程安全的）</p>
<h2 id=""><a href="#" class="headerlink" title="+"></a>+</h2><p>“+”可以字符串与字符串或非字符串拼接在一起，形成字符串。<br>java使用StringBuffer对象重载了+号操作符，通过append方法对字符串进行拼接。（JAVA不允许对其他操作符进行重载）<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">The Java language provides special support for the string concatenation operator ( + ), and for conversion of  other objects to strings. String concatenation is implemented  through the StringBuilder(or StringBuffer) class and its append method.</span><br></pre></td></tr></table></figure></p>
<p>我们来看下JAVA如何对+号进行重载的。<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">public class AddDemo &#123;</span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        String test = &quot;fsh&quot;;</span><br><span class="line">        String test1 = &quot;love&quot;;</span><br><span class="line">        String test3 = &quot;money&quot;;</span><br><span class="line">        String word = test+test1+test3;</span><br><span class="line">        System.out.println(word);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>我们使用java内置的查看字节码命令 javap -c -verbose AddDemo.class<br>我们来看下解析字节码的内容<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">E:\fsh_workspace\code\java-template\target\classes\String&gt;javap -c -verbose AddDemo.class</span><br><span class="line">Classfile /E:/fsh_workspace/code/java-template/target/classes/String/AddDemo.class</span><br><span class="line">  Last modified 2018-1-23; size 836 bytes</span><br><span class="line">  MD5 checksum 8cde17f102d21f567c820cfc77731d45</span><br><span class="line">  Compiled from &quot;AddDemo.java&quot;</span><br><span class="line">public class String.AddDemo</span><br><span class="line">  minor version: 0</span><br><span class="line">  major version: 52</span><br><span class="line">  flags: ACC_PUBLIC, ACC_SUPER</span><br><span class="line">Constant pool:</span><br><span class="line">   #1 = Methodref          #12.#31        // java/lang/Object.&quot;&lt;init&gt;&quot;:()V</span><br><span class="line">   #2 = String             #32            // fsh</span><br><span class="line">   #3 = String             #33            // love</span><br><span class="line">   #4 = String             #34            // money</span><br><span class="line">   #5 = Class              #35            // java/lang/StringBuilder</span><br><span class="line">   #6 = Methodref          #5.#31         // java/lang/StringBuilder.&quot;&lt;init&gt;&quot;:()V</span><br><span class="line">   #7 = Methodref          #5.#36         // java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span><br><span class="line">   #8 = Methodref          #5.#37         // java/lang/StringBuilder.toString:()Ljava/lang/String;</span><br><span class="line">   #9 = Fieldref           #38.#39        // java/lang/System.out:Ljava/io/PrintStream;</span><br><span class="line">  #10 = Methodref          #40.#41        // java/io/PrintStream.println:(Ljava/lang/String;)V</span><br><span class="line">  #11 = Class              #42            // String/AddDemo</span><br><span class="line">  #12 = Class              #43            // java/lang/Object</span><br><span class="line">  #13 = Utf8               &lt;init&gt;</span><br><span class="line">  #14 = Utf8               ()V</span><br><span class="line">  #15 = Utf8               Code</span><br><span class="line">  #16 = Utf8               LineNumberTable</span><br><span class="line">  #17 = Utf8               LocalVariableTable</span><br><span class="line">  #18 = Utf8               this</span><br><span class="line">  #19 = Utf8               LString/AddDemo;</span><br><span class="line">  #20 = Utf8               main</span><br><span class="line">  #21 = Utf8               ([Ljava/lang/String;)V</span><br><span class="line">  #22 = Utf8               args</span><br><span class="line">  #23 = Utf8               [Ljava/lang/String;</span><br><span class="line">  #24 = Utf8               test</span><br><span class="line">  #25 = Utf8               Ljava/lang/String;</span><br><span class="line">  #26 = Utf8               test1</span><br><span class="line">  #27 = Utf8               test3</span><br><span class="line">  #28 = Utf8               word</span><br><span class="line">  #29 = Utf8               SourceFile</span><br><span class="line">  #30 = Utf8               AddDemo.java</span><br><span class="line">  #31 = NameAndType        #13:#14        // &quot;&lt;init&gt;&quot;:()V</span><br><span class="line">  #32 = Utf8               fsh</span><br><span class="line">  #33 = Utf8               love</span><br><span class="line">  #34 = Utf8               money</span><br><span class="line">  #35 = Utf8               java/lang/StringBuilder</span><br><span class="line">  #36 = NameAndType        #44:#45        // append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span><br><span class="line">  #37 = NameAndType        #46:#47        // toString:()Ljava/lang/String;</span><br><span class="line">  #38 = Class              #48            // java/lang/System</span><br><span class="line">  #39 = NameAndType        #49:#50        // out:Ljava/io/PrintStream;</span><br><span class="line">  #40 = Class              #51            // java/io/PrintStream</span><br><span class="line">  #41 = NameAndType        #52:#53        // println:(Ljava/lang/String;)V</span><br><span class="line">  #42 = Utf8               String/AddDemo</span><br><span class="line">  #43 = Utf8               java/lang/Object</span><br><span class="line">  #44 = Utf8               append</span><br><span class="line">  #45 = Utf8               (Ljava/lang/String;)Ljava/lang/StringBuilder;</span><br><span class="line">  #46 = Utf8               toString</span><br><span class="line">  #47 = Utf8               ()Ljava/lang/String;</span><br><span class="line">  #48 = Utf8               java/lang/System</span><br><span class="line">  #49 = Utf8               out</span><br><span class="line">  #50 = Utf8               Ljava/io/PrintStream;</span><br><span class="line">  #51 = Utf8               java/io/PrintStream</span><br><span class="line">  #52 = Utf8               println</span><br><span class="line">  #53 = Utf8               (Ljava/lang/String;)V</span><br><span class="line">&#123;</span><br><span class="line">  public String.AddDemo();</span><br><span class="line">    descriptor: ()V</span><br><span class="line">    flags: ACC_PUBLIC</span><br><span class="line">    Code:</span><br><span class="line">      stack=1, locals=1, args_size=1</span><br><span class="line">         0: aload_0</span><br><span class="line">         1: invokespecial #1                  // Method java/lang/Object.&quot;&lt;init&gt;&quot;:()V</span><br><span class="line">         4: return</span><br><span class="line">      LineNumberTable:</span><br><span class="line">        line 6: 0</span><br><span class="line">      LocalVariableTable:</span><br><span class="line">        Start  Length  Slot  Name   Signature</span><br><span class="line">            0       5     0  this   LString/AddDemo;</span><br><span class="line"></span><br><span class="line">  public static void main(java.lang.String[]);</span><br><span class="line">    descriptor: ([Ljava/lang/String;)V</span><br><span class="line">    flags: ACC_PUBLIC, ACC_STATIC</span><br><span class="line">    Code:</span><br><span class="line">      stack=2, locals=5, args_size=1</span><br><span class="line">         0: ldc           #2                  // String fsh</span><br><span class="line">         2: astore_1</span><br><span class="line">         3: ldc           #3                  // String love</span><br><span class="line">         5: astore_2</span><br><span class="line">         6: ldc           #4                  // String money</span><br><span class="line">         8: astore_3</span><br><span class="line">         9: new           #5                  // class java/lang/StringBuilder</span><br><span class="line">        12: dup</span><br><span class="line">        13: invokespecial #6                  // Method java/lang/StringBuilder.&quot;&lt;init&gt;&quot;:()V</span><br><span class="line">        16: aload_1</span><br><span class="line">        17: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span><br><span class="line">        20: aload_2</span><br><span class="line">        21: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span><br><span class="line">        24: aload_3</span><br><span class="line">        25: invokevirtual #7                  // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;</span><br><span class="line">        28: invokevirtual #8                  // Method java/lang/StringBuilder.toString:()Ljava/lang/String;</span><br><span class="line">        31: astore        4</span><br><span class="line">        33: getstatic     #9                  // Field java/lang/System.out:Ljava/io/PrintStream;</span><br><span class="line">        36: aload         4</span><br><span class="line">        38: invokevirtual #10                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V</span><br><span class="line">        41: return</span><br><span class="line">      LineNumberTable:</span><br><span class="line">        line 8: 0</span><br><span class="line">        line 9: 3</span><br><span class="line">        line 10: 6</span><br><span class="line">        line 11: 9</span><br><span class="line">        line 12: 33</span><br><span class="line">        line 13: 41</span><br><span class="line">      LocalVariableTable:</span><br><span class="line">        Start  Length  Slot  Name   Signature</span><br><span class="line">            0      42     0  args   [Ljava/lang/String;</span><br><span class="line">            3      39     1  test   Ljava/lang/String;</span><br><span class="line">            6      36     2 test1   Ljava/lang/String;</span><br><span class="line">            9      33     3 test3   Ljava/lang/String;</span><br><span class="line">           33       9     4  word   Ljava/lang/String;</span><br><span class="line">&#125;</span><br><span class="line">SourceFile: &quot;AddDemo.java&quot;</span><br></pre></td></tr></table></figure></p>
<img src="/blog/images/java/java_add_class.png">
<p>从上图可以看出java使用StringBuilder重载了+好</p>
<h2 id="concat"><a href="#concat" class="headerlink" title="concat"></a>concat</h2><p>concat方法只能将字符串和字符串进行拼接<br>如果要实现a，拼接b，concat的实现方式为：<br><figure class="highlight java"><table><tr><td class="code"><pre><span class="line">a.concat(b)</span><br></pre></td></tr></table></figure></p>
<p>下面我们来看下concat的实现原理<br><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">public String concat(String str) &#123;</span><br><span class="line">     int otherLen = str.length();</span><br><span class="line">     if (otherLen == 0) &#123;</span><br><span class="line">         return this;</span><br><span class="line">     &#125;</span><br><span class="line">     int len = value.length;</span><br><span class="line">     //创建字符数组，并且把当前对象的值：value从0开始拷贝到字符数组中</span><br><span class="line">     char buf[] = Arrays.copyOf(value, len + otherLen);</span><br><span class="line">     //从buf数组的len位置（不包括）处将拷贝到字符数组中</span><br><span class="line">     str.getChars(buf, len);</span><br><span class="line">     //通过字符数组生成一个新的字符对象</span><br><span class="line">     return new String(buf, true);</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure></p>
<ul>
<li>可以看出，如果b为null则方法抛NullPointException异常</li>
<li>该方法主要通过一个字符数组，存放拼接的两个字符串，然后再生成一个新的字符串对象。所以如果做大量的字符串拼接时，使用concat，会产生大量的中间对象。</li>
</ul>
<h2 id="StringBuilder"><a href="#StringBuilder" class="headerlink" title="StringBuilder"></a>StringBuilder</h2><p>对于大量字符串的拼接时，我们通常会被告知使用StringBuilder。并且，听同事说，当使用”+” 做字符串拼接时，JVM会吧帮我们优化成StringBuilder。<br>现在我们来看下StringBuilder的实现原理<br><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> StringBuilder <span class="title">append</span><span class="params">(String str)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">super</span>.append(str);</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">this</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>我们进到StringBuilder的父类中，看下append方法的实现<br><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * The value is used for character storage.</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"> <span class="keyword">char</span>[] value;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment">  * The count is the number of characters used.</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"> <span class="keyword">int</span> count;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> AbstractStringBuilder <span class="title">append</span><span class="params">(String str)</span> </span>&#123;</span><br><span class="line"> 	<span class="comment">//拼接的字符串允许为null</span></span><br><span class="line">     <span class="keyword">if</span> (str == <span class="keyword">null</span>)</span><br><span class="line">         <span class="keyword">return</span> appendNull();</span><br><span class="line">     <span class="keyword">int</span> len = str.length();</span><br><span class="line">     ensureCapacityInternal(count + len);</span><br><span class="line">     <span class="comment">//从count处开始，将字符串str拷贝到字符数组value中，拷贝的长度为（len-0）</span></span><br><span class="line">     str.getChars(<span class="number">0</span>, len, value, count);</span><br><span class="line">     count += len;</span><br><span class="line">     <span class="keyword">return</span> <span class="keyword">this</span>;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">getChars</span><span class="params">(<span class="keyword">int</span> srcBegin, <span class="keyword">int</span> srcEnd, <span class="keyword">char</span> dst[], <span class="keyword">int</span> dstBegin)</span> </span>&#123;</span><br><span class="line">     <span class="keyword">if</span> (srcBegin &lt; <span class="number">0</span>) &#123;</span><br><span class="line">         <span class="keyword">throw</span> <span class="keyword">new</span> StringIndexOutOfBoundsException(srcBegin);</span><br><span class="line">     &#125;</span><br><span class="line">     <span class="keyword">if</span> (srcEnd &gt; value.length) &#123;</span><br><span class="line">         <span class="keyword">throw</span> <span class="keyword">new</span> StringIndexOutOfBoundsException(srcEnd);</span><br><span class="line">     &#125;</span><br><span class="line">     <span class="keyword">if</span> (srcBegin &gt; srcEnd) &#123;</span><br><span class="line">         <span class="keyword">throw</span> <span class="keyword">new</span> StringIndexOutOfBoundsException(srcEnd - srcBegin);</span><br><span class="line">     &#125;</span><br><span class="line">     <span class="comment">//从dest开始，将value拷贝到dst数组中，长度为：srcEnd-srcBegin</span></span><br><span class="line">     System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure></p>
<ul>
<li>从源码可以看到，StringBuilder的append方法允许拼接的字符串为null，如果为null会转换为“null”的字符串</li>
<li>可以看出StringBuilder对象有二个类变量：字符数组型的类变量value用来保存拼接的字符，int类型的类变量count，记录字符的长度</li>
<li>当进行字符串拼接的时候，先对字符串数组value扩容，并且将拼接的字符串拷贝到字符数组中，然后修改字符长度count</li>
<li>可以看到当大量字符串进行拼接的时候，每次拼接不会产生中间对象，至始至终都是一个StringBuilder对象。</li>
</ul>
<blockquote>
<blockquote>
<p>参考：<br><a href="https://stackoverflow.com/questions/47605/string-concatenation-concat-vs-operator" target="_blank" rel="external">https://stackoverflow.com/questions/47605/string-concatenation-concat-vs-operator</a></p>
</blockquote>
</blockquote>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/java/" rel="tag"># java</a>
          
            <a href="/blog/tags/String/" rel="tag"># String</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/01/19/Spring全局异常处理/" rel="next" title="Spring全局异常处理">
                <i class="fa fa-chevron-left"></i> Spring全局异常处理
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/01/23/kafka随记/" rel="prev" title="kafka随记">
                kafka随记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNjY5NS8xMzIzMA=="></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/head.jpg"
               alt="Fang ShuHao" />
          <p class="site-author-name" itemprop="name">Fang ShuHao</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives">
                <span class="site-state-item-count">135</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories">
                <span class="site-state-item-count">35</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/blog/tags">
                <span class="site-state-item-count">93</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#"><span class="nav-number">1.</span> <span class="nav-text">+</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#concat"><span class="nav-number">2.</span> <span class="nav-text">concat</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#StringBuilder"><span class="nav-number">3.</span> <span class="nav-text">StringBuilder</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Fang ShuHao</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  



  
  

  

  

  

  


  

</body>
</html>
